<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin/head :: head" th:with="title=理财统计添加">
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="formfilter">
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>用户id:</label>
                <div class="layui-input-block">
                    <input type="text" id="userId" name="userId"  lay-verify="required|userId" autocomplete="off" placeholder="用户id" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>本金:</label>
                <div class="layui-input-block">
                    <input type="text" id="principal" name="principal"  lay-verify="required|principal" autocomplete="off" placeholder="本金" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>利息:</label>
                <div class="layui-input-block">
                    <input type="text" id="interest" name="interest"  lay-verify="required|interest" autocomplete="off" placeholder="利息" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>总金:</label>
                <div class="layui-input-block">
                    <input type="text" id="totalGold" name="totalGold"  lay-verify="required|totalGold" autocomplete="off" placeholder="总金" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>统计时间:</label>
                <div class="layui-input-block">
                    <input type="text" id="censusTime" name="censusTime"  lay-verify="required|censusTime" autocomplete="off" placeholder="统计时间" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>币种id:</label>
                <div class="layui-input-block">
                    <input type="text" id="currencyId" name="currencyId"  lay-verify="required|currencyId" autocomplete="off" placeholder="币种id" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>周期（天）:</label>
                <div class="layui-input-block">
                    <input type="text" id="cycle" name="cycle"  lay-verify="required|currencyId" autocomplete="off" placeholder="周期（天）" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>利率:</label>
                <div class="layui-input-block">
                    <input type="text" id="rate" name="rate"  lay-verify="required|currencyId" autocomplete="off" placeholder="利率" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>


    layui.use(['laydate', 'layer', 'jquery','liuQi'], function () {
            var form = layui.form,
                    liuQi = layui.liuQi,
                    laydate = layui.laydate;

            form.render();

            //自定义验证规则
            form.verify({
                //radio验证
                otherReq: function(value,item){
                    var $ = layui.$;
                    var verifyName=$(item).attr('name')
                            , verifyType=$(item).attr('type')
                            ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                            ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                            ,isTrue= verifyElem.is(':checked')//是否命中校验
                            ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                    if(!isTrue || !value){
                        //定位焦点
                        focusElem.css(verifyType=='radio'?{"color":"#FF5722"}:{"border-color":"#FF5722"});
                        //对非输入框设置焦点
                        focusElem.first().attr("tabIndex","1").css("outline","0").blur(function() {
                            focusElem.css(verifyType=='radio'?{"color":""}:{"border-color":""});
                        }).focus();
                        return '必填项不能为空';
                    }
                },
                userId: function (value) {
                },
                principal: function (value) {
                },
                interest: function (value) {
                },
                totalGold: function (value) {
                },
                censusTime: function (value) {
                },
                currencyId: function (value) {
                },
            })
            //监听提交
            form.on('submit(formSubmit)', function (data) {
                data=data.field;
                liuQi.ajax("/admin/miningCensus/add",data,
                        function (data) {
                            //关闭
                            parent.layer.msg(data.msg);
                            parent.layui.table.reload('currentTableId');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                );
                return false;
            });
    });
</script>

</body>
</html>